package com.epalmpay.controller.shop.shopuser;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.dto.member.MemberConsumeOutDTO;
import com.epalmpay.dto.member.MemberInDTO;
import com.epalmpay.dto.member.MemberListOutDTO;
import com.epalmpay.dto.member.MemberOutDTO;
import com.epalmpay.dto.member.MemberTradeDetailInDTO;
import com.epalmpay.entity.Member;
import com.epalmpay.entity.Page;
import com.epalmpay.service.management.IUserService;
import com.epalmpay.service.member.IMemberGradeService;
import com.epalmpay.service.member.IMemberService;
import com.epalmpay.util.PropertyCopyUtil;
import com.epalmpay.util.Tools;

/** 
 * 说明：会员
 * 创建人：gwn
 * 创建时间：2017-05-15
 */
@Controller
@RequestMapping(value="/shop/member")
public class MemberShopController  extends BaseController{
	
	@Resource
	private IMemberService memberService;
	
	@Resource
	private IMemberGradeService memberGradeService;
	
	@Resource
	private IUserService userService;
	
	
	/**
	 * 显示会员列表
	 * @param memberInDTO
	 * @param pageDTO
	 * @return
	 */
	@RequestMapping(value="/list")
	@ResponseBody
	public MemberListOutDTO  listMember(MemberInDTO memberInDTO,PageDTO pageDTO){
		MemberListOutDTO memberListOutDTO=new MemberListOutDTO();
		try {
			Page page=Tools.pageEmtity(pageDTO);
			//取得所有会员等级
			memberListOutDTO.setMemberGradeList(memberGradeService.getGradeList(memberInDTO));
			//获取会员列表列表信息
			List<MemberOutDTO> memberOutDTOList = memberService.getShopMemberList(memberInDTO.getShopId(),memberInDTO.getGradeId(),memberInDTO.getFromName(),memberInDTO.getWxsubStaus(),memberInDTO.getJoinStart(),memberInDTO.getJoinEnd(),memberInDTO.getName(),page);			
			memberListOutDTO.setMemberOutDTOList(memberOutDTOList);
			memberListOutDTO.setPage(page); 
			memberListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return memberListOutDTO;
		} catch (ApplicationException ae) { 
			memberListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 memberListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return memberListOutDTO;
	}		
	
	
	/**
	 * 查看会员详情  根基id huixian 
	 * @param memberOut
	 * @return
	 */
	@RequestMapping(value="/findShopMemberDetailById")
	@ResponseBody
	
	public MemberOutDTO  findShopMemberDetailById(MemberInDTO memberOut){
		MemberOutDTO memberOuts=new MemberOutDTO();
		Member member=new Member();
		try {   
			member.setId(memberOut.getId());
			
			
			Member members=memberService.findShopMemberDetailById(member);
			if(members!=null){
				PropertyCopyUtil.copyPropertiesExclude(members,memberOuts);
				memberOuts.setErrorCode(Rescode.SUCCESS, "查询成功");
				return memberOuts;
			}else{
				memberOuts.setErrorCode("-1", "未查询到记录");
			}
		} catch (Exception e) { 
			memberOuts.setErrorCode("-1", "处理出现异常");
			e.printStackTrace();
		}
		memberOuts.setErrorCode("-2", "处理失败");
		return memberOuts;
	}
	
	
	/**
	 * 交易记录列表查询
	 * @param memberInDTO
	 * @param pageDTO
	 * @return
	 */
	@RequestMapping(value="/tradeDetailList")
	@ResponseBody
	public MemberListOutDTO  shopTradeDetailList(MemberTradeDetailInDTO memberTradeDetailInDTO,PageDTO pageDTO){
		MemberListOutDTO memberListOutDTO=null;
		try {
			Page page=Tools.pageEmtity(pageDTO);
			//查询会员信息
			MemberConsumeOutDTO memberConsumeOutDTO= memberService.queryShopMemberConsumeData(memberTradeDetailInDTO);
			
			//获取会员列表列表信息
			memberListOutDTO = memberService.queryShopTradeDetail(memberTradeDetailInDTO,page);	
			memberListOutDTO.setMemberConsumeOutDTO(memberConsumeOutDTO);
			memberListOutDTO.setPage(page); 
			memberListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return memberListOutDTO;
		} catch (ApplicationException ae) { 
			memberListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}
		 catch (Exception e) { 
			 memberListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return memberListOutDTO;
	}	
	
	
	
	
}
